package com.cy.demo.service.impl;

import com.cy.demo.mapper.AddressMapper;
import com.cy.demo.mapper.ProductMapper;
import com.cy.demo.pojo.Address;
import com.cy.demo.pojo.Product;
import com.cy.demo.service.IAddressService;
import com.cy.demo.service.IDistrictService;
import com.cy.demo.service.IProductService;
import com.cy.demo.service.ex.AddressCountLimitException;
import com.cy.demo.service.ex.AddressNotFoundException;
import com.cy.demo.service.ex.InsertException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class IProductServiceImpl implements IProductService {



    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> findHotList() {
        List<Product> list = productMapper.findHotList();
        for (Product product : list) {
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);
        }
        return list;
    }

    public List<Product> findNewList() {
        List<Product> list = productMapper.findNewList();
        for (Product product : list) {
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);
        }
        return list;
    }

    @Override
    public Product findById(int id) throws Exception {

        Product product = productMapper.findById(id);
        if (product != null)
        {
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);

          return product;
        }else {
            throw new Exception("该商品不存在");
        }
    }
}
